package com.example.wac.entity.common;

import java.io.Serializable;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wuancheng
 * @description
 * @date 2022-08-05 15:54:00
 */
public class ReqDTO extends HashMap<String, Object> implements Serializable {
    private static final long serialVersionUID = -2017880068779780714L;

    public ReqDTO() {
    }

    public Object getObject(final Object key) {
        return this.get(key);
    }

    public String getString(final Object key) {
        Object answer = this.get(key);
        return answer != null ? answer.toString() : null;
    }

    public Boolean getBoolean(final Object key) {
        Object answer = this.get(key);
        if (answer != null) {
            if (answer instanceof Boolean) {
                return (Boolean)answer;
            }

            if (answer instanceof String) {
                return new Boolean((String)answer);
            }

            if (answer instanceof Number) {
                Number n = (Number)answer;
                return n.intValue() != 0 ? Boolean.TRUE : Boolean.FALSE;
            }
        }

        return null;
    }

    public Number getNumber(final Object key) {
        Object answer = this.get(key);
        if (answer != null) {
            if (answer instanceof Number) {
                return (Number)answer;
            }

            if (answer instanceof String) {
                try {
                    String text = (String)answer;
                    return NumberFormat.getInstance().parse(text);
                } catch (ParseException var4) {
                }
            }
        }

        return null;
    }

    public Byte getByte(final Object key) {
        Number answer = this.getNumber(key);
        if (answer == null) {
            return null;
        } else {
            return answer instanceof Byte ? (Byte)answer : new Byte(answer.byteValue());
        }
    }

    public Short getShort(final Object key) {
        Number answer = this.getNumber(key);
        if (answer == null) {
            return null;
        } else {
            return answer instanceof Short ? (Short)answer : new Short(answer.shortValue());
        }
    }

    public Integer getInteger(final Object key) {
        Number answer = this.getNumber(key);
        if (answer == null) {
            return null;
        } else {
            return answer instanceof Integer ? (Integer)answer : new Integer(answer.intValue());
        }
    }

    public Long getLong(final Object key) {
        Number answer = this.getNumber(key);
        if (answer == null) {
            return null;
        } else {
            return answer instanceof Long ? (Long)answer : new Long(answer.longValue());
        }
    }

    public Float getFloat(final Object key) {
        Number answer = this.getNumber(key);
        if (answer == null) {
            return null;
        } else {
            return answer instanceof Float ? (Float)answer : new Float(answer.floatValue());
        }
    }

    public Double getDouble(final Object key) {
        Number answer = this.getNumber(key);
        if (answer == null) {
            return null;
        } else {
            return answer instanceof Double ? (Double)answer : new Double(answer.doubleValue());
        }
    }

    public Map getMap(final Object key) {
        Object answer = this.get(key);
        return answer != null && answer instanceof Map ? (Map)answer : null;
    }

    public Object getObject(Object key, Object defaultValue) {
        Object answer = this.get(key);
        return answer != null ? answer : defaultValue;
    }

    public String getString(Object key, String defaultValue) {
        String answer = this.getString(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Boolean getBoolean(Object key, Boolean defaultValue) {
        Boolean answer = this.getBoolean(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Number getNumber(Object key, Number defaultValue) {
        Number answer = this.getNumber(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Byte getByte(Object key, Byte defaultValue) {
        Byte answer = this.getByte(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Short getShort(Object key, Short defaultValue) {
        Short answer = this.getShort(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Integer getInteger(Object key, Integer defaultValue) {
        Integer answer = this.getInteger(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Long getLong(Object key, Long defaultValue) {
        Long answer = this.getLong(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Float getFloat(Object key, Float defaultValue) {
        Float answer = this.getFloat(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Double getDouble(Object key, Double defaultValue) {
        Double answer = this.getDouble(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public Map getMap(Object key, Map defaultValue) {
        Map answer = this.getMap(key);
        if (answer == null) {
            answer = defaultValue;
        }

        return answer;
    }

    public boolean getBooleanValue(final Object key) {
        Boolean booleanObject = this.getBoolean(key);
        return booleanObject == null ? false : booleanObject;
    }

    public byte getByteValue(final Object key) {
        Byte byteObject = this.getByte(key);
        return byteObject == null ? 0 : byteObject;
    }

    public short getShortValue(final Object key) {
        Short shortObject = this.getShort(key);
        return shortObject == null ? 0 : shortObject;
    }

    public int getIntValue(final Object key) {
        Integer integerObject = this.getInteger(key);
        return integerObject == null ? 0 : integerObject;
    }

    public long getLongValue(final Object key) {
        Long longObject = this.getLong(key);
        return longObject == null ? 0L : longObject;
    }

    public float getFloatValue(final Object key) {
        Float floatObject = this.getFloat(key);
        return floatObject == null ? 0.0F : floatObject;
    }

    public double getDoubleValue(final Object key) {
        Double doubleObject = this.getDouble(key);
        return doubleObject == null ? 0.0D : doubleObject;
    }

    public boolean getBooleanValue(final Object key, boolean defaultValue) {
        Boolean booleanObject = this.getBoolean(key);
        return booleanObject == null ? defaultValue : booleanObject;
    }

    public byte getByteValue(final Object key, byte defaultValue) {
        Byte byteObject = this.getByte(key);
        return byteObject == null ? defaultValue : byteObject;
    }

    public short getShortValue(final Object key, short defaultValue) {
        Short shortObject = this.getShort(key);
        return shortObject == null ? defaultValue : shortObject;
    }

    public int getIntValue(final Object key, int defaultValue) {
        Integer integerObject = this.getInteger(key);
        return integerObject == null ? defaultValue : integerObject;
    }

    public long getLongValue(final Object key, long defaultValue) {
        Long longObject = this.getLong(key);
        return longObject == null ? defaultValue : longObject;
    }

    public float getFloatValue(final Object key, float defaultValue) {
        Float floatObject = this.getFloat(key);
        return floatObject == null ? defaultValue : floatObject;
    }

    public double getDoubleValue(final Object key, double defaultValue) {
        Double doubleObject = this.getDouble(key);
        return doubleObject == null ? defaultValue : doubleObject;
    }
}
